﻿using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace UIExpand
{
    public class ColorChanger : MonoBehaviour
    {

        public enum GraphicType
        {
            Image,
            SpriteRender,
            Text,
        }
        public GraphicType graphicType = GraphicType.Image;
        public Color[] colors;

        public void ChangeToIndex(int idx)
        {
            if (idx >= colors.Length || colors[idx] == null)
                return;

            if (graphicType == GraphicType.Image)
            {
                ChangeColor_Image(colors[idx]);
            }
               
            else if(graphicType == GraphicType.Text)
            {
                ChangeColor_Text(colors[idx]);
            }
            else
            {
                ChangeColor_SpriteRenderer(colors[idx]);
            }
                

        }

        public void ChangeColor_SpriteRenderer(Color color)
        {
            SpriteRenderer sr = GetComponent<SpriteRenderer>();
            if (sr != null)
            {
                sr.color = color;
            }  
        }

        public void ChangeColor_Image(Color color)
        {
            Image image = GetComponent<Image>();

            if (image != null)
            {
                image.color = color;
            }
        }

        public void ChangeColor_Text(Color color)
        {
            Text t = GetComponent<Text>();

            if (t != null)
            {
                t.color = color;
            }
            else
            {
                TextMeshProUGUI tm = GetComponent<TextMeshProUGUI>();
                tm.color = color;
            }
        }
    }
}

